package com.cloud.stock;

import com.cloud.controller.TestController;

import java.io.File;
import java.util.*;

/**
 * @author: create by God of SJF
 * @version: v1.0
 * @description: com.cloud.stock
 * @date:2021/8/25
 */
public class 转JSON1 {

    public static void main(String[] arg)throws Exception{

        File file = new File("/Users/libin/Desktop/码流转/");
        File[] fileList = file.listFiles();
        Arrays.sort( fileList, new Comparator()
        {
            public int compare(Object o1, Object o2) {
                return new Long(((File)o1).lastModified()).compareTo(new Long(((File) o2).lastModified()));
            }
        });
        for (File thisFile:fileList) {
            String name = thisFile.getName();
            System.out.println(name);
            name = name.replaceAll("Untitled","");
            File file2 = new File("/Users/libin/Desktop/码流转2/"+name);
            Scanner scanner = new Scanner(thisFile);
            StringBuilder sb = new StringBuilder();
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                sb.append(line);
                if(line.indexOf("}") != -1){
                    String sbFinal = sb.toString().replaceAll(" ","");
                    sbFinal= sbFinal.replace("},","}");
                    sbFinal= sbFinal.replace("","");
                    sbFinal=sbFinal.replace("{\"RECORDS\":[","");
                    sbFinal=sbFinal.replace("]}","");
                    List<String> list = new ArrayList<>();
                    list.add(sbFinal+"\r\n");
                    sb = new StringBuilder();
                    TestController.writeFile(file2.getAbsolutePath(),list);
                }
            }
            thisFile.delete();
        }

//        File file = new File("/Users/libin/Desktop/码流转/Untitled3.json");

    }
}
